package com.foxit.pdf2pdf.web.common;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.log4j.Logger;
/**
 * @author shaojie_zhuo
 * @version 1.0
 * String Utils.
 */
public final class FXStringUtils {
	
	private static final Logger log =Logger.getLogger(FXStringUtils.class);
	/**
	 * Check whether the string is empty or null.(for Java 1.5)
	 * @param strValue string to check.
	 * @return return true if the string is null or empty, otherwise return false.
	 */
	public static boolean IsNullOrEmpty(String strValue)
	{
		if (strValue == null || strValue.isEmpty())
			return true;
		else
			return false;
	}
	
	/**  
	 * ��InputStreamת����ĳ���ַ������String  
	 * @param in  
	 * @param encoding  
	 * @return  
	 * @throws Exception  
	 */  
    public static String inputStreamTOString(InputStream in,String encoding){  
        ByteArrayOutputStream outStream = new ByteArrayOutputStream(); 
        String stringInfo="";
        byte[] data = new byte[1024];  
        int count = -1;  
        try {
			while((count = in.read(data,0,1024)) != -1){
				 outStream.write(data, 0, count);
			}  
			stringInfo=new String(outStream.toByteArray(),encoding);
		} catch (IOException e) {
			log.error(e);
			return null;
		}finally{
			try {
				in.close();
				outStream.close();
			} catch (IOException e) {
				log.error(e);
				return null;
			}
		}
        data = null;  
        return stringInfo;  
    }  
}